// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
//import Vue from 'vue'
//import App from './App'
//import router from './router'
//
//Vue.config.productionTip = false
//
///* eslint-disable no-new */
//new Vue({
//el: '#app',
//router,
//template: '<App/>',
//components: { App }
//})

import Vue from 'vue'

import MuseUI from 'muse-ui'
import 'muse-ui/dist/muse-ui.css'
Vue.use(MuseUI)
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/dist/css/swiper.css'
Vue.use(VueAwesomeSwiper)
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App.vue'
import router from './router'
import axios from 'axios'
import Clipboard from 'clipboard'

import global_ from './components/Global'
import VueClipboard from 'vue-clipboard2'
import './components/Toast/toast.css'
import Toast from './components/Toast/index'

Vue.use(Toast)


Vue.prototype.GLOBAL = global_

Vue.use(VueClipboard)

//import locale from 'element-ui/lib/locale/lang/en'

//Vue.prototype.axios = axios;
//Vue.config.productionTip = false

  // axios 配置
axios.defaults.timeout = 50000;
//根目录
axios.defaults.baseURL = '';
  // http request 拦截器
axios.interceptors.request.use(
config => {
    if (localStorage.token) {
      config.params  = config.params||{}
      config.params.token = `${localStorage.token}`;
    }
    return config;
},
err => {
    return Promise.reject(err);
});

// http response 拦截器
// 监测是否登陆了
axios.interceptors.response.use(
	  response => {
	  	
	  	if(response.data.code==401){
	  		 router.replace({
             path: 'login',
             query: {redirect: router.currentRoute.fullPath}
          
           })
	  	}else if(response.data.code==402){
	  		 router.replace({
             path: 'factoryList',
             query: {redirect: router.currentRoute.fullPath}
          
           })
	  	}  	
//  switch () {
//    case 401:
//      // 401 清除token信息并跳转到登录页面
//         router.replace({
//           path: 'login2',
//           query: {redirect: router.currentRoute.fullPath}
//        
//         })
//    case 402:
//       	  		 router.replace({
//           path: 'factoryList',
//           query: {redirect: router.currentRoute.fullPath}
//        
//         })   
//         	
//
//  }
    return response;
},
error => {
    throw error
});
Vue.prototype.axios = axios;
Vue.use(ElementUI)

Vue.config.productionTip = false
// 判断是否需要登录权限 以及是否登录
router.beforeEach((to, from, next) => {
   if (to.meta.requireAuth) {// 判断是否需要登录权限
   if (localStorage.getItem('token')) {// 判断是否登录
next()
   } else {// 没登录则跳转到登录界面
next({
path: '/login',
query: {redirect: to.fullPath}
})
   }
   } else {
   next()
   }
})






/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>',
//axios
})
